import DataItemModel from "../../../cfw/mvc/DataItemModel";
import { CookieToyModelEnum } from "../../../public/GameEnumConfig";
import User from "../../db/User";
import { ItemState } from "../../../cfw/tools/Define";
import Player from "../../player/Player";
/**
* 糕点装饰物
**/
export default class CookieToyModel extends DataItemModel {


	static CLASS_NAME: string = 'CookieToyModel'

	init(id, data) {
		super.init(id, data)
		this.setState(User.instance().getCookieToyState(this.ID))
	}

	isOpen() {
		return Player.instance().getLevel() >= this.getOpenLevel()
	}

	getOpenLevel() {
		let num = this.data[CookieToyModelEnum.adge]
		return num ? num : 0
	}

	setState(s) {
		super.setState(s)
		User.instance().setCookieToyState(this.ID, s)
	}

	getScale() {
		return this.data[CookieToyModelEnum.scale]
	}

	needBuy() {
		let list = this.getCostItem()
		return list && list.length > 0 && this.getState() != ItemState.GOT;
	}

	// icon
	getIcon() {
		return 'texture/cookie_toy/' + this.data[CookieToyModelEnum.icon]
	}
	// 消费道具
	getCostItem() {
		return this.data[CookieToyModelEnum.costItem]
	}
	// 索引
	getIndex() {
		return this.data[CookieToyModelEnum.index]
	}



}